package org.lanqiao.netctoss.controller.service;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.lanqiao.netctoss.entity.Acount;
import org.lanqiao.netctoss.entity.Buss;
import org.lanqiao.netctoss.service.impl.AcountServiceImpl;
import org.lanqiao.netctoss.service.impl.BussServiceImpl;

/**
 * Servlet implementation class AddServiceServlet
 */
public class AddServiceServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public AddServiceServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		if(request.getParameter("add")!=null){
			String aco_card = request.getParameter("card");	
			System.out.println("shuruwei:"+aco_card);
			//String aco_user = new AcountBussImpl().selAcountBycard(new Acount(aco_card));
			String aco_user = new AcountServiceImpl().selectAcountBycard(new Acount(aco_card)).getAco_user();
			System.out.println("zhiwei:::"+aco_user);
			HttpSession session =  request.getSession();
			session.setAttribute("user",aco_user);
			session.setAttribute("card", aco_card);
			request.getRequestDispatcher("../view/service/service_add.jsp").forward(request, response);
		}else{
			String bus_card = request.getParameter("card");	
			/*List<Acount> la=  new AcountBussImpl().selAcountNo(new Acount(bus_card));*/
			List<Acount> la = new AcountServiceImpl().selectAcountNo(new Acount(bus_card));
			int bus_ano=0;
			String bus_name="";
			for(Acount l:la){
				bus_ano=l.getAco_no();
				bus_name=l.getAco_name();
			}
			String bus_taname=request.getParameter("type");
			String bus_ip = request.getParameter("ip");
			String bus_os = request.getParameter("os");
			String psw1 = request.getParameter("psw1");
			String psw2 = request.getParameter("psw2");
			//boolean b = new BussBussImpl().insBuss(new Buss(bus_ano,bus_card,bus_name,bus_os,psw1,bus_ip,bus_taname));
			int b = new BussServiceImpl().insertBuss(new Buss(bus_ano,bus_card,bus_name,bus_os,psw1,bus_ip,bus_taname));
			if(b>0){
				request.getRequestDispatcher("../view/service/service_add.jsp").forward(request, response);
			}						
		}
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
